package com.itheima.stock.handler;



import com.itheima.stock.enums.CodeEnum;
import com.itheima.stock.exception.StockException;
import com.itheima.stock.response.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
 * 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 处理自定义业务异常
     * @param e 业务异常
     */
    @ExceptionHandler(StockException.class)
    public ResponseResult<?> handleStockException(StockException e) {

        return ResponseResult.error(e.getCode());
    }
    /**
     * 处理未知异常
     * @param e 未知异常
     */
    @SuppressWarnings("all")
    @ExceptionHandler(Exception.class)
    public ResponseResult<?>  handleUnKnownException(Exception e) {
        log.error("系统异常：", e);
        //todo
        e.printStackTrace();
        return ResponseResult.error(CodeEnum.SYSTEM_ERROR);
    }
}
